/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.modelo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import util.JPAUtil;

/**
 *
 * @author Gilberto
 */
@Entity
@Table(name = "ecf_impressora")
public class Impressora implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID")
    private Integer id;
    @Column(name = "NUMERO")
    private Integer numero;
    @Size(max = 10)
    @Column(name = "CODIGO")
    private String codigo;
    @Size(max = 20)
    @Column(name = "SERIE")
    private String serie;
    @Size(max = 250)
    @Column(name = "IDENTIFICACAO")
    private String identificacao;
    @Size(max = 2)
    @Column(name = "MC")
    private String mc;
    @Size(max = 2)
    @Column(name = "MD")
    private String md;
    @Size(max = 2)
    @Column(name = "VR")
    private String vr;
    @Size(max = 7)
    @Column(name = "TIPO")
    private String tipo;
    @Size(max = 30)
    @Column(name = "MARCA")
    private String marca;
    @Size(max = 30)
    @Column(name = "MODELO")
    private String modelo;
    @Size(max = 30)
    @Column(name = "MODELO_ACBR")
    private String modeloAcbr;
    @Size(max = 2)
    @Column(name = "MODELO_DOCUMENTO_FISCAL")
    private String modeloDocumentoFiscal;
    @Size(max = 30)
    @Column(name = "VERSAO")
    private String versao;
    @Column(name = "LE")
    private Character le;
    @Column(name = "LEF")
    private Character lef;
    @Column(name = "MFD")
    private Character mfd;
    @Column(name = "LACRE_NA_MFD")
    private Character lacreNaMfd;
    @Size(max = 60)
    @Column(name = "DOCTO")
    private String docto;
    @Column(name = "DATA_INSTALACAO_SB")
    @Temporal(TemporalType.DATE)
    private Date dataInstalacaoSb;
    @Size(max = 8)
    @Column(name = "HORA_INSTALACAO_SB")
    private String horaInstalacaoSb;
    @Size(max = 5)
    @Column(name = "NUMERO_ECF")
    private String numeroEcf;
    @Column(name = "MF_ADICIONAL")
    private Character mfAdicional;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idEcfImpressora")
    private List<Configuracao> configuracaoCollection ;

    public Impressora() {
    }

    public Impressora(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getNumero() {
        return numero;
    }

    public void setNumero(Integer numero) {
        this.numero = numero;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getSerie() {
        return serie;
    }

    public void setSerie(String serie) {
        this.serie = serie;
    }

    public String getIdentificacao() {
        return identificacao;
    }

    public void setIdentificacao(String identificacao) {
        this.identificacao = identificacao;
    }

    public String getMc() {
        return mc;
    }

    public void setMc(String mc) {
        this.mc = mc;
    }

    public String getMd() {
        return md;
    }

    public void setMd(String md) {
        this.md = md;
    }

    public String getVr() {
        return vr;
    }

    public void setVr(String vr) {
        this.vr = vr;
    }

    public String getTipo() {
        return tipo;
    }

    public void setTipo(String tipo) {
        this.tipo = tipo;
    }

    public String getMarca() {
        return marca;
    }

    public void setMarca(String marca) {
        this.marca = marca;
    }

    public String getModelo() {
        return modelo;
    }

    public void setModelo(String modelo) {
        this.modelo = modelo;
    }

    public String getModeloAcbr() {
        return modeloAcbr;
    }

    public void setModeloAcbr(String modeloAcbr) {
        this.modeloAcbr = modeloAcbr;
    }

    public String getModeloDocumentoFiscal() {
        return modeloDocumentoFiscal;
    }

    public void setModeloDocumentoFiscal(String modeloDocumentoFiscal) {
        this.modeloDocumentoFiscal = modeloDocumentoFiscal;
    }

    public String getVersao() {
        return versao;
    }

    public void setVersao(String versao) {
        this.versao = versao;
    }

    public Character getLe() {
        return le;
    }

    public void setLe(Character le) {
        this.le = le;
    }

    public Character getLef() {
        return lef;
    }

    public void setLef(Character lef) {
        this.lef = lef;
    }

    public Character getMfd() {
        return mfd;
    }

    public void setMfd(Character mfd) {
        this.mfd = mfd;
    }

    public Character getLacreNaMfd() {
        return lacreNaMfd;
    }

    public void setLacreNaMfd(Character lacreNaMfd) {
        this.lacreNaMfd = lacreNaMfd;
    }

    public String getDocto() {
        return docto;
    }

    public void setDocto(String docto) {
        this.docto = docto;
    }

    public Date getDataInstalacaoSb() {
        return dataInstalacaoSb;
    }

    public void setDataInstalacaoSb(Date dataInstalacaoSb) {
        this.dataInstalacaoSb = dataInstalacaoSb;
    }

    public String getHoraInstalacaoSb() {
        return horaInstalacaoSb;
    }

    public void setHoraInstalacaoSb(String horaInstalacaoSb) {
        this.horaInstalacaoSb = horaInstalacaoSb;
    }

    public String getNumeroEcf() {
        return numeroEcf;
    }

    public void setNumeroEcf(String numeroEcf) {
        this.numeroEcf = numeroEcf;
    }

    public Character getMfAdicional() {
        return mfAdicional;
    }

    public void setMfAdicional(Character mfAdicional) {
        this.mfAdicional = mfAdicional;
    }

    public Collection<Configuracao> getConfiguracaoCollection() {
        return configuracaoCollection;
    }

    public void setConfiguracaoCollection(List<Configuracao> configuracaoCollection) {
        this.configuracaoCollection = configuracaoCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Impressora)) {
            return false;
        }
        Impressora other = (Impressora) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.modelo.Impressora[ id=" + id + " ]";
    }

    public static Impressora retornaImpressoraPorid(Integer id) {
        EntityManager em = JPAUtil.retornarFabrica().createEntityManager();
        Query q = em.createQuery("FROM Impressora f WHERE f.id = ?");
        q.setParameter(1, id);
        Impressora retorno;
        try {
            retorno = (Impressora) q.getSingleResult();
            em.close();
            return retorno;
        } catch (javax.persistence.NoResultException e) {
            em.close();
            return null;
        }
    }

    public static List<Impressora> retornaImpressoras() {
        EntityManager em = JPAUtil.retornarFabrica().createEntityManager();
        Query q = em.createQuery("FROM Impressora e");
        List<Impressora> list = q.getResultList();
        em.close();
        return list;
    }
    public Impressora salvar() {
        return (Impressora) JPAUtil.mergeObjeto(this);
    }

    public Impressora salvarCaixas(String ip) {
        return (Impressora) JPAUtil.mergeObjetoCaixa(ip, this);
    }
}
